package com.qf.zyh.web.controller;

import com.qf.zyh.common.Const;
import com.qf.zyh.entity.Product;
import com.qf.zyh.services.Impl.ProductSerImpl;
import com.qf.zyh.services.ProductSer;
import com.qf.zyh.util.StrUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@WebServlet("/pro")
public class ProductController extends BaseServlet{
    ProductSer ps = new ProductSerImpl();
    public String getProid(HttpServletRequest req, HttpServletResponse resp){
        //获取pid，根据tid查找数据
       Integer pid = StrUtils.toint(req.getParameter("pid"));
        Product pd = ps.getid(pid);
        req.setAttribute("goods",pd);
        return Const.SysConst.FORWARD+"goodsDetail.jsp";
    }
    public String getGoodsById(HttpServletRequest req, HttpServletResponse resp){
        //分页显示数据，不但需要获取数据，还要获取页码,和每页显示行数
        Integer tid = StrUtils.toint(req.getParameter("tid"));
        Integer pageIndex = StrUtils.toint(req.getParameter("pageIndex"));
        Map<String,Object> maps = ps.getProPage(tid,pageIndex,8);
        req.setAttribute("map",maps);
        return Const.SysConst.FORWARD+"goodsList.jsp";
    }
}
